// import {MAILING_ADDRESS} from 'actionsTypes'
import getDataService from '../services/getData'
import {Toast} from 'antd-mobile'

export const orderDetails_view = (data, callBack) => {
    return (dispatch, getState) => {
        Toast.hide(); //加载前 先关闭其他加载中的提示框 避免提示框一直存在的bug
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        getDataService.orderView(data).then(resultData => {
            Toast.hide();
            if (resultData.code == 1000) {
                if (callBack) {
                    callBack(resultData.data)
                }
            } else {
                Toast.info(resultData.msg, 2);
            }

        })
    }
}

//获取代办所需资料
export const requirements = (data, callBack) => {
    return (dispatch, getState) => {
        Toast.hide();
        Toast.loading("", 30, () => Toast.info("网络错误", 2));
        //通过orderid获取carNumber
        getDataService.getInfo(data).then(resultData => {
            if (resultData.code == 1000) {
                return {carNumber:resultData.data.carNumber,inspectionType:resultData.data.inspectionType,driveType:resultData.data.driveType};
            }
            else {
                Toast.hide();
                Toast.info(resultData.msg, 2);
            }
        }).then((data) => {
            return data.carNumber&&getDataService.requirements(data);
        }).then(resultData => {
            if(resultData) {
                Toast.hide();
                if (resultData.code == 1000) {
                    if (callBack) {
                        callBack(resultData.data)
                    }
                } else {
                    Toast.info(resultData.msg, 2);
                }
            }
        }).catch((error)=>{
            Toast.info('请求数据出错', 2);
        })
    }
};

//获取 完结订单的评价情况
export const evaluationDetails= (data, callBack) => {
	return (dispatch, getState) => {
		Toast.hide(); //加载前 先关闭其他加载中的提示框 避免提示框一直存在的bug
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		getDataService.evaluationView(data).then(resultData=>{
			Toast.hide();
			if (resultData.code == 1000) {
				if(callBack){
					callBack(resultData.data);
				}
			}
			else {
				Toast.info(resultData.msg, 2);
			}
		})
	}
};
//获取 完结订单的评价情况
export const setEvaluationDetails= (data, callBack) => {
	return (dispatch, getState) => {
		Toast.hide(); //加载前 先关闭其他加载中的提示框 避免提示框一直存在的bug
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		getDataService.setEevaluationView(data).then(resultData=>{
			Toast.hide();
			if (resultData.code == 1000) {
				if(callBack){
					callBack(resultData);
				}
			}
			else {
				Toast.info(resultData.msg, 2);
			}
		})
	}
};


